package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.domain.QgPayWithdrawalDetail;
import com.ruoyi.web.dto.QgPayWithdrawalDetailAddDTO;
import com.ruoyi.web.dto.QgPayWithdrawalDetailRejectDTO;
import com.ruoyi.web.service.IQgPayWithdrawalDetailService;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * QGPay提现明细Controller
 *
 * @date 2023-03-15
 */
@RestController
@RequestMapping("/qg-pay/withdrawal-detail")
@AllArgsConstructor
public class QgPayWithdrawalDetailController extends BaseController {
    private final IQgPayWithdrawalDetailService qgPayWithdrawalDetailService;

    /**
     * 查询QGPay提现明细列表
     */
    @PreAuthorize("@ss.hasPermi('qgPay:withdrawalDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(QgPayWithdrawalDetail qgPayWithdrawalDetail) {
        startPage();
        List<QgPayWithdrawalDetail> list = qgPayWithdrawalDetailService.selectQgPayWithdrawalDetailList(qgPayWithdrawalDetail);
        return getDataTable(list);
    }

    /**
     * 导出QGPay提现明细列表
     */
    @PreAuthorize("@ss.hasPermi('qgPay:withdrawalDetail:export')")
    @Log(title = "QGPay提现明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QgPayWithdrawalDetail qgPayWithdrawalDetail) {
        List<QgPayWithdrawalDetail> list = qgPayWithdrawalDetailService.selectQgPayWithdrawalDetailList(qgPayWithdrawalDetail);
        ExcelUtil<QgPayWithdrawalDetail> util = new ExcelUtil<QgPayWithdrawalDetail>(QgPayWithdrawalDetail.class);
        util.exportExcel(response, list, "QGPay提现明细数据");
    }

    /**
     * 获取QGPay提现明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('qgPay:withdrawalDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(qgPayWithdrawalDetailService.selectQgPayWithdrawalDetailById(id));
    }

    /**
     * 创建提现
     *
     * @param dto dto
     * @return {@link AjaxResult}
     * @since 2023/3/15 17:32
     */
    @RepeatSubmit
    @PostMapping
    public AjaxResult add(@RequestBody @Validated QgPayWithdrawalDetailAddDTO dto) {
        qgPayWithdrawalDetailService.add(dto);
        return success();
    }

    /**
     * 审核通过
     *
     * @param id id
     * @return {@link AjaxResult}
     * @since 2023/3/15 17:32
     */
    @RepeatSubmit
    @PostMapping("/approve/{id}")
    public AjaxResult approve(@PathVariable("id") Long id) {
        qgPayWithdrawalDetailService.approve(id);
        return success();
    }

    /**
     * 审核拒绝
     *
     * @param dto dto
     * @return {@link AjaxResult}
     * @since 2023/3/15 17:32
     */
    @RepeatSubmit
    @PostMapping("/reject")
    public AjaxResult reject(@RequestBody @Validated QgPayWithdrawalDetailRejectDTO dto) {
        qgPayWithdrawalDetailService.reject(dto);
        return success();
    }

    /**
     * h5分页查询
     *
     * @param condition 查询条件
     * @return {@link TableDataInfo}
     * @since 2023/3/17 10:51
     */
    @GetMapping("/app/page")
    public TableDataInfo appPage(QgPayWithdrawalDetail condition) {
        startPage();
        List<QgPayWithdrawalDetail> list = qgPayWithdrawalDetailService.appPage(condition);
        return getDataTable(list);
    }
}
